package com.hgd.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.hgd.client.admin.Admin;
import com.hgd.client.admin.AdminImplDelegate;
import com.hgd.client.admin.AdminImplService;
import com.hgd.client.ms.Device;
import com.hgd.client.ms.MSImplDelegate;
import com.hgd.client.ms.MSImplService;
import com.hgd.client.ms.ManagementStation;
import com.hgd.client.ms.Task;

public class MSAction extends ActionSupport {
	
	private List<Admin> admins = new ArrayList<Admin>(); 
	private List<Device> deviceList = new ArrayList<Device>();
	private List<Task> taskList = new ArrayList<Task>();
	private List<ManagementStation> MSList = new ArrayList<ManagementStation>();
	private ManagementStation station = new ManagementStation();
	private int addFlag;
	private Integer msId;
	private AdminImplService adminImplService = new AdminImplService();
	private AdminImplDelegate adminImplDelegate = adminImplService.getAdminImplPort();
	
	private MSImplService msImplService = new MSImplService();
	private MSImplDelegate msImplDelegate = msImplService.getMSImplPort();
	
	ActionContext context = ActionContext.getContext(); 
	Map params = context.getParameters(); 
	
	public String getCommonAdmin() throws Exception{
		//admins = adminImplDelegate.getCommonAdmin();
		MSList = msImplDelegate.getMS();
		return SUCCESS;
	}
	/**
	 * 获取管理站设备
	 * @return
	 * @throws Exception
	 */
	public String getDeviceByMS() throws Exception{
		params = context.getParameters(); 
		String[] id=(String[])params.get("msId");
		int msId = Integer.parseInt(id[0]);
		deviceList = msImplDelegate.getDeviceByMS(msId);
		return SUCCESS;
	}
	
	public String getTaskByMS() throws Exception{
		params = context.getParameters(); 
		String[] id=(String[])params.get("msId");
		int msId = Integer.parseInt(id[0]);
		taskList = msImplDelegate.getTaskByMS(msId);
		return SUCCESS;
	}
	/**
	 * 获取管理站
	 * @return
	 * @throws Exception
	 */
	public String getMS() throws Exception{
		MSList = msImplDelegate.getMS();
		return SUCCESS;
	}
	/**
	 * 获取单个管理站
	 * @return
	 * @throws Exception
	 */
	public String getMSById() throws Exception{
		station = msImplDelegate.getMSById(msId);
		System.out.println(msId);
		return SUCCESS;
	}
	/**
	 * 添加管理站
	 * @return
	 * @throws Exception
	 */
	public String msAdd() throws Exception{
		String addResult = SUCCESS;	
		addFlag = msImplDelegate.msAdd(station);
		if (addFlag==1) {
			addResult = SUCCESS;
		}else{
			addResult = ERROR;
		}
		return addResult;
	}
	/**
	 * 删除管理站
	 * @return
	 * @throws Exception
	 */
	public String msDel() throws Exception{
		int flag = 0;
		String delResult;
		flag = msImplDelegate.msDel(msId);
		if (flag==1) {
			delResult = SUCCESS;
		}else{
			delResult = ERROR;
		}
		return delResult;
	}
	/**
	 * 修改管理站
	 * @return
	 * @throws Exception
	 */
	public String msMod() throws Exception{
		int flag = 0;
		String modResult;
		System.out.println(station.getMSId());
		flag = msImplDelegate.msMod(station);
		if (flag==1) {	
			modResult = SUCCESS;
		}else{
			modResult = ERROR;
		}
		return modResult;
	}
	public List<Task> getTaskList() {
		return taskList;
	}

	public void setTaskList(List<Task> taskList) {
		this.taskList = taskList;
	}

	public List<Admin> getAdmins() {
		return admins;
	}

	public void setAdmins(List<Admin> admins) {
		this.admins = admins;
	}

	public List<Device> getDeviceList() {
		return deviceList;
	}

	public void setDeviceList(List<Device> deviceList) {
		this.deviceList = deviceList;
	}
	
	public List<ManagementStation> getMSList() {
		return MSList;
	}

	public void setMSList(List<ManagementStation> mSList) {
		MSList = mSList;
	}

	public ManagementStation getStation() {
		return station;
	}

	public void setStation(ManagementStation station) {
		this.station = station;
	}

	public int getAddFlag() {
		return addFlag;
	}

	public void setAddFlag(int addFlag) {
		this.addFlag = addFlag;
	}
	public Integer getMsId() {
		return msId;
	}
	public void setMsId(Integer msId) {
		this.msId = msId;
	}	
	
}